<?php
/**
 * Zhub - A PHP Framework For API Developer
 *
 * This file is part of the Zhub package.
 *
 * (c) YiLong Fan <fantiq@163.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author fanyilong <fantiq@163.com>
 * @copyright 2017 fanyilong. All rights reserved.
 * @package Zhub
 * @date 18-3-2
 */

namespace Zhub\Console;


use Zhub\Console\Output\ColorEnum;

class Output
{
    const COLOR_FORMAT = "\033[3%dm%s\033[0m";

    private $content = '';

    public function __construct($content = '')
    {
        $this->content = $content;
    }

    public function append(string $content)
    {
        $this->content .= $content;
    }

    public function send()
    {
        echo $this->content;
    }

    public function color(int $color, string $txt)
    {
        $this->append(PHP_OS === 'linux' ? sprintf(self::COLOR_FORMAT, $color, $txt) : $txt);
    }

    public function warning(string $content)
    {
        $this->color(ColorEnum::YELLOW, $content);
    }

    public function success(string $content)
    {
        $this->color(ColorEnum::GREEN, $content);
    }
}
